import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class PropertyDetailPage extends StatefulWidget {
  @override
  _PropertyDetailPageState createState() => _PropertyDetailPageState();
}

class _PropertyDetailPageState extends State<PropertyDetailPage> {
  var _scrollController = ScrollController();
  var _oldShowState = false;
  var _showNarrow = false;

  bool _onNotification(ScrollNotification notification) {
    print("_scrollController.offset == $_scrollController.offset");

    bool show = _scrollController.offset > 100;
    if (show != _oldShowState) {
      _oldShowState = show;
      setState(() {
        _showNarrow = show;
      });
    }
    return true;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomSheet: Container(
        height: 200.h,
        color: Colors.redAccent,
      ),
      body: ConstrainedBox(
        constraints: BoxConstraints.expand(),
        child: Stack(
          children: <Widget>[
            Container(
              height: 200.h,
              color: Colors.redAccent,
            ),

          NotificationListener(
            onNotification: _onNotification,
            child: CustomScrollView(
              controller: _scrollController,
              slivers: <Widget>[
                //AppBar，包含一个导航栏
                SliverAppBar(
                  elevation: 10.h,
                  backgroundColor: Colors.grey,
                  title: Text(
                    "房产详情",
                  ),
                  leading: Icon(Icons.star),
                  actions: <Widget>[
                    Icon(Icons.star),
                    SizedBox(
                      width: 20.w,
                    ),
                    Container(
                      child: Icon(Icons.message),
                      margin: EdgeInsets.only(right: 50.w),
                    ),
                  ],
                  pinned: true,
                  expandedHeight: 500.h,
                  flexibleSpace: FlexibleSpaceBar(
                    stretchModes: <StretchMode>[StretchMode.zoomBackground],
                    collapseMode: CollapseMode.parallax,
                    background: Image.asset(
                      "assets/images/cover_img.jpg",
                      fit: BoxFit.cover,
                    ),
                  ),
                ),

                //List
                SliverFixedExtentList(
                  itemExtent: 50.0,
                  delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
                    //创建列表项
                    return Container(
                      alignment: Alignment.center,
                      color: Colors.lightBlue[100 * (index % 9)],
                      child: Text('list item $index'),
                    );
                  }, childCount: 50 //50个列表项
                  ),
                ),
              ],
            ),
          ),

          ],
        ),
      ),
    );
  }
}
